package com.bw.wxy.mvp.base.view;

import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.blankj.utilcode.util.BarUtils;
import com.bw.wxy.common.LogUtils;
import com.bw.wxy.mvp.base.prsenter.IPresenter;

import javax.inject.Inject;

public abstract class BaseFragment<P extends IPresenter> extends Fragment implements IFragment,IView {

    @Inject
    protected P p;
    private View inflate;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        inflate = inflater.inflate(bindLayout(),container, false);
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//            getActivity().getWindow().getDecorView().setSystemUiVisibility(
//                    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//                            | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
//            //把状态栏标记为浅色，然后状态栏的字体颜色自动转换为深色
//        }
//        BarUtils.setStatusBarColor(getActivity(), addBarColor());
//        //防止contentview绘制到状态栏中
//        BarUtils.addMarginTopEqualStatusBarHeight(addStatusView());
        initView();
        inject();
        getLifecycle().addObserver(p);
        initData();
        return inflate;
    }

//    public abstract int addBarColor();
//
//    public abstract View addStatusView();

    @Override
    public void onDestroy() {
        super.onDestroy();
        getLifecycle().removeObserver(p);
    }

    public <T extends View> T f(int id){
        return inflate.findViewById(id);
    }

    @Override
    public void startPage(Bundle bundle, Class clazz) {
        Intent intent = new Intent(getActivity(),clazz);
        if (bundle!=null){
            intent.putExtras(intent);
        }
        getActivity().startActivity(intent);
    }

    public void startPage(Class clazz) {
        startPage(null,clazz);
    }


    @Override
    public void showDialog() {

    }

    @Override
    public void hideDialog() {

    }

    @Override
    public void showMessage(String msg) {
        LogUtils.e(msg);
    }
}

